from django.test import TestCase
from django.contrib.auth.models import User
from .models import UserProfile


class UserProfileModelTest(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            username='testuser',
            password='testpass123',
            email='test@example.com'
        )
    
    def test_user_profile_creation(self):
        """测试用户扩展信息自动创建"""
        profile = self.user.profile
        self.assertEqual(profile.user.username, 'testuser')
        self.assertEqual(profile.points, 0)
    
    def test_user_profile_str_method(self):
        """测试__str__方法"""
        profile = self.user.profile
        self.assertEqual(str(profile), 'testuser的完整信息')
    
    def test_user_profile_properties(self):
        """测试属性方法"""
        profile = self.user.profile
        info = profile.get_user_info()
        self.assertEqual(info['username'], 'testuser')
        self.assertEqual(info['email'], 'test@example.com')